Remove unreachable NotImplementedException array-with-choice#129491
Open
StephenMolloy wants to merge 1 commit into
Open
Remove unreachable NotImplementedException array-with-choice#129491StephenMolloy wants to merge 1 commit into
StephenMolloy wants to merge 1 commit into
Conversation
…eflection-based XmlSerializer (dotnet#1400) WriteArray in ReflectionXmlSerializationReader threw NotImplementedException when memberMapping.ChoiceIdentifier was non-null. That memberMapping is a freshly constructed local whose ChoiceIdentifier is always null, so the throw was unreachable dead code. The choice value for an array-typed choice element is recorded by the calling WriteElement against the owning member after WriteArray returns, so the reflection-based serializer already round-trips these types correctly. Add a regression test covering an [XmlChoiceIdentifier] member where one of the choice element types is itself an array (its element mapping is an ArrayMapping). The test runs in both the codegen and ReflectionOnly XmlSerializer test projects. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes an unreachable NotImplementedException in the reflection-based XmlSerializer reader’s array-handling path and adds a regression test to ensure [XmlChoiceIdentifier] works when one of the choice element types is itself an array (ArrayMapping).
Changes:
- Removed dead/unreachable
memberMapping.ChoiceIdentifier != nullthrow inReflectionXmlSerializationReader.WriteArray. - Added a new round-trip test covering an
[XmlChoiceIdentifier]member where one choice element is an array (int[]), validating both value and populated choice-identifier array. - Added a small helper type + enum used by the new test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs | Removes unreachable NotImplementedException and documents why choice tracking is handled by the caller (WriteElement). |
| src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs | Adds regression test and supporting types for array-typed choice elements ([XmlChoiceIdentifier] + int[]). |
Open
3 tasks
mangod9
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WriteArray in ReflectionXmlSerializationReader threw NotImplementedException when memberMapping.ChoiceIdentifier was non-null. That memberMapping is a freshly constructed local whose ChoiceIdentifier is always null, so the throw was unreachable dead code. The choice value for an array-typed choice element is recorded by the calling WriteElement against the owning member after WriteArray returns, so the reflection-based serializer already round-trips these types correctly.
Add a regression test covering an [XmlChoiceIdentifier] member where one of the choice element types is itself an array (its element mapping is an ArrayMapping). The test runs in both the codegen and ReflectionOnly XmlSerializer test projects.
Fixes #1400
(Well, not really fixing, because the exception was impossible to hit. But also added some test coverage assurance just in case.)